package com.example.classmanageapp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.classmanageapp.utils.SysUtils;
import com.example.classmanageapp.utils.Utility;

import de.hdodenhof.circleimageview.CircleImageView;

public class PersonActivity extends Activity {

    private ImageButton img_back;
    private CircleImageView mine_avatar;
    private TextView mine_nick;
    private TextView edit;
    private RelativeLayout mine_sign_relative;
    private TextView sign_content;
    private RelativeLayout rl_account;
    private TextView account_content;
    private RelativeLayout rl_nick;
    private TextView tv_nick;
    private RelativeLayout rl_sex;
    private TextView tv_sex;
    private RelativeLayout rl_email;
    private TextView tv_mail;
    private Button exit_btn;

    private Context context;

    public static Bitmap headimage;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SysUtils.setStatusBarColor(this, true, 0);
        SysUtils.setSkin(this);
        setContentView(R.layout.activity_person);
        context = this;

        Init();
    }

    private void Init() {


        img_back = findViewById((R.id.img_back));

        mine_avatar = findViewById((R.id.mine_avatar));

        mine_nick = findViewById((R.id.mine_nick));

        edit = findViewById((R.id.edit));

        mine_sign_relative = findViewById((R.id.mine_sign_relative));

        sign_content = findViewById((R.id.sign_content));

        rl_account = findViewById((R.id.rl_account));

        account_content = findViewById((R.id.account_content));

        rl_nick = findViewById((R.id.rl_nick));

        tv_nick = findViewById((R.id.tv_nick));

        rl_sex = findViewById((R.id.rl_sex));

        tv_sex = findViewById((R.id.tv_sex));

        rl_email = findViewById((R.id.rl_email));

        tv_mail = findViewById((R.id.tv_mail));

        exit_btn = findViewById((R.id.exit_btn));


        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });


        mine_avatar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                startActivityForResult(new Intent(context, PhotoActivity.class), 1);

            }
        });


        edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                startActivity(new Intent(context, CompileActivity.class));
            }
        });

        exit_btn.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                Utility.savePatternByKey(PersonActivity.this, Utility.IS_LOGIN, "0");
                Intent intent = new Intent(PersonActivity.this, LoginActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (headimage != null) {
            mine_avatar.setImageBitmap(headimage);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


    @Override
    public void onBackPressed() {
        finish();
    }
}
